#include "pch.hpp"
#include "vertices.hpp"




GuiVertex::GuiVertex()
	: position(0, 0, 0)
	, tex(0, 0)
	, col(0, 0, 0, 0)
	, channel(0, 0, 0, 0)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////

StaticReflection GuiVertex::reflect()
{
	BOOST_STATIC_ASSERT(offsetof(GuiVertex, position) == 0);
	BOOST_STATIC_ASSERT(offsetof(GuiVertex, tex) == 12);
	BOOST_STATIC_ASSERT(offsetof(GuiVertex, col) == 20);
	BOOST_STATIC_ASSERT(offsetof(GuiVertex, channel) == 36);
	BOOST_STATIC_ASSERT(sizeof(GuiVertex) == 52);

	static const StaticReflectionElement table[] = {
		{ "POSITION", 0, Format::R32G32B32_FLOAT,    0 },
		{ "TEXCOORD", 0, Format::R32G32_FLOAT,       0 },
		{ "TEXCOORD", 1, Format::R32G32B32A32_FLOAT, 0 },
		{ "TEXCOORD", 2, Format::R32G32B32A32_SINT,  0 },
		0,
	};

	return StaticReflection(table, sizeof(GuiVertex));
}
///////////////////////////////////////////////////////////////////////////////////////////////////




MeshVertex::MeshVertex()
	: position(0, 0, 0)
	, normal(0, 0, 0)
	, tex(0, 0)
	, tangent(0, 0, 0)
	, bitangent(0, 0, 0)
{}
///////////////////////////////////////////////////////////////////////////////////////////////////

StaticReflection MeshVertex::reflect()
{
	// Verify that the VertexDescription we give to D3D11 is the same
	// as the real layout in memory, in case someone is stupid enough to
	// change it without modifying this code.
	BOOST_STATIC_ASSERT(offsetof(MeshVertex, position) == 0);
	BOOST_STATIC_ASSERT(offsetof(MeshVertex, normal) == 12);
	BOOST_STATIC_ASSERT(offsetof(MeshVertex, tex) == 24);
	BOOST_STATIC_ASSERT(offsetof(MeshVertex, tangent) == 32);
	BOOST_STATIC_ASSERT(offsetof(MeshVertex, bitangent) == 44);
	BOOST_STATIC_ASSERT(sizeof(MeshVertex) == 56);

	static const StaticReflectionElement table[] = {
		{ "POSITION", 0, Format::R32G32B32_FLOAT, 0 },
		{ "NORMAL",   0, Format::R32G32B32_FLOAT, 0 },
		{ "TEXCOORD", 0, Format::R32G32_FLOAT,    0 },
		{ "TEXCOORD", 1, Format::R32G32B32_FLOAT, 0 }, //< Tangent
		{ "TEXCOORD", 2, Format::R32G32B32_FLOAT, 0 }, //< Bitangent
		0,
	};

	return StaticReflection(table, sizeof(MeshVertex));
}
///////////////////////////////////////////////////////////////////////////////////////////////////




boostext::iostreams::bin_istream& operator>>(boostext::iostreams::bin_istream& stream, MeshVertex& vert)
{
	stream >> vert.position;
	stream >> vert.normal;

	stream >> vert.tex;

	stream >> vert.tangent;
	stream >> vert.bitangent;

	return stream;
}
///////////////////////////////////////////////////////////////////////////////////////////////////

boostext::iostreams::bin_ostream& operator<<(boostext::iostreams::bin_ostream& stream, const MeshVertex& vert)
{
	stream << vert.position;
	stream << vert.normal;

	stream << vert.tex;

	stream << vert.tangent;
	stream << vert.bitangent;

	return stream;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
